#!/bin/bash

# 清除历史文字
clear

# 检查当前文件夹下是否存在 Miao-Yunzai.sh 文件
if [ ! -f "Miao-Yunzai.sh" ]; then
    echo -e "\e[1;31m未找到 Miao-Yunzai.sh 文件，脚本结束。\e[0m"
    exit 0
else
    echo -e "\e[1;32m找到 Miao-Yunzai.sh 文件，继续处理。\e[0m"
fi

# 查找是否存在连着的 redis-server --stop-writes-on-bgsave-error
if grep -q "redis-server --stop-writes-on-bgsave-error" "Miao-Yunzai.sh"; then
    echo -e "\e[1;32m找到 redis-server --stop-writes-on-bgsave-error，开始替换。\e[0m"

    # 替换内容
    sed -i 's|redis-server --stop-writes-on-bgsave-error|redis-server /etc/redis/redis.conf --stop-writes-on-bgsave-error|g' "Miao-Yunzai.sh"
    echo -e "\e[1;32m替换完成。\e[0m"
else
    echo -e "\e[1;31m未找到 redis-server --stop-writes-on-bgsave-error，脚本结束。\e[0m"
    exit 0
fi

# 下载新的 redis.conf 文件并覆盖
echo "开始下载新的 redis.conf 文件。"
if curl -o "/etc/redis/redis.conf" "https://gitee.com/bling_yshs/res-repo/raw/master/yunzai/redis/redis.conf"; then
    echo -e "\e[1;32m下载并覆盖 /etc/redis/redis.conf 成功。\e[0m"
else
    echo -e "\e[1;31m下载失败，请检查网络连接或URL。\e[0m"
    exit 1
fi

echo -e "\e[1;32m脚本执行完毕。\e[0m"
